<?php

namespace app\api\controller\delivery;

use app\api\model\order\Order as OrderModel;
use app\api\controller\Controller;
use app\api\model\settings\Setting as SettingModel;
use app\api\service\pay\PayService;
use app\common\model\app\App as AppModel;
use app\common\model\order\OrderAddress;
use app\common\model\order\OrderReferee as OrderRefereeModel;
use app\common\model\product\ProductClaim;
use app\common\model\store\Clerk;
use app\common\model\store\Store;
use app\common\model\store\Remarks;
use app\common\model\supplier\Service as ServiceModel;
use app\common\model\shopper\Shopper;
use app\common\model\user\User as UserModel;
use app\common\service\order\OrderCompleteService;
use app\Request;
use app\common\model\supplier\User as SupplierUserModel;
use GuzzleHttp\Client;

/**
 * 普通订单
 */
class Order extends Controller
{
    /**
     * 我的订单列表
     */
    public function lists($dataType)
    {
        try {
            $data = $this->postData();
            $model = new OrderModel;
            $user = $this->getUser();
            $is_shopper = 0;
            if($dataType =='shipping' || $dataType =='received_order' || $dataType =='shopper_comment'){
                $is_shopper = 1;
            }
            $list = $model->getDeliveryList($dataType, $data, $user,$is_shopper);
            $show_alipay = PayService::isAlipayOpen($data['pay_source'], $user['app_id']);
            $app = AppModel::detail();
            $mch_id = $app['mchid'];
            return $this->renderSuccess('', compact('list', 'show_alipay', 'mch_id'));
        } catch (\Exception $exception) {
            return $this->renderError($exception->getMessage());
        }
    }

    public function getOrderNum()
    {
        $user = $this->getUser();
        $clerk = Clerk::getByUser($user);

        if(!$clerk){
            $clerk = Shopper::shopperDetail($user['user_id']);
            $clerk['user_id'] = $user['user_id'];
            $clerk['clerk_id'] = $clerk['id'];
            $is_shopper = 1;
            $dateTypeAry = ['shipping','received_order','shopper_comment'];

        }else{
            $is_shopper = 0;
            $dateTypeAry = ['delivery','received','comment'];
        }
        $countlist = [];
        $vkey = 0;
        foreach ($dateTypeAry as $vvalue) {
            $model = new OrderModel;
            $countlist[$vkey] = $model->getDeliveryCount($vvalue, [], $user,$is_shopper);
            $vkey++;
            if($vvalue=='delivery'){
                $countlist[$vkey] = $model->getDeliveryCount($vvalue, ['order_source'=>30], $user,$is_shopper);
                $vkey++;
            }
        }
        return $this->renderSuccess('', compact('countlist'));
    }

    public function receiving(Request $request)
    {
        try {
            $params = $request->param();
            $model = new OrderModel;
            $user = $this->getUser();
            $model->receiving($params, $user);

            $wxmodel = \app\supplier\model\order\Order::detail($params['order_id']);
            // 20240715 kevin 接单即调用微信发货接口
            if($wxmodel['pay_price']>0){
                $wxmodel->wxDelivery();
            }

            return $this->renderSuccess('操作成功');
        } catch (\Exception $exception) {
            return $this->renderError($exception->getMessage());
        }
    }

    /**
     * 转单
     * @param Request $request
     * @return \think\response\Json
     */
    public function transferOrder(Request $request)
    {
        try {

            $model = new OrderModel;
            $params = $request->param();
            $stype = $params['stype'];
            $order = $model->where(['order_id' => $params['order_id']])->find();

            if((new Shopper()) -> where('id', $order['store_clerk_id'])->count()){
                $is_transfer_ckid = 2;
            }else{
                $is_transfer_ckid = 1;
            }
            $is_store_clerk_id = 1;
            if($stype==3){ //特殊配送员原路返回
//                $order = $model->where(['order_id' => $params['order_id']])->find();
                //取货后转单一定要拍照
//                if($order['is_claim'] == 1){
//                    if(!isset($params['image'])||$params['image']==''){
//                        return $this->renderError('请先拍照上传');
//                    }
//                }

                $clerk = (new Clerk()) -> where('clerk_id', $order['transfer_ckid'])->find();
                $data = [
                    'shop_supplier_id' => $order['shop_supplier_id'],
                    'store_id' => $order['transfer_spid'], //原门店id
                    'order_id' => $order['order_id'],
                    'image' => $params['image']??'',
                    'store_clerk_id' => $order['transfer_ckid'],//原配送员id
                    'store_clerk_phone' => $clerk['mobile'],
                    'ctype' => 1

                ];
                ProductClaim::createData($data);

                $user_id_json = $order['user_id_json'];
                $user_id_array = json_decode($user_id_json,true);


                $count = count($user_id_array) - 3;
                $user_id = $user_id_array[$count]??0; //转单人的id
                $transfer_ckid = 0;
                $transfer_spid = 0;
                if($user_id){
                    $clerk = (new Clerk())-> where('user_id',$user_id) -> find();
                    if(!$clerk){
                        $clerk = (new Shopper())-> where('uid',$user_id) -> find();
                        $transfer_spid = $order['transfer_spid'];
                        $transfer_ckid = $clerk['id'];
                    }else{

                        $transfer_spid = $clerk['store_id'];
                        $transfer_ckid = $clerk['clerk_id'];
                    }
                }

                $model -> updateUserIdJson($order['store_clerk_id'],$order['order_id'],$order['user_id_json'],$order['is_store_clerk_id']);


                //更新订单
                $order->save([
                    'is_transfer' => 1,
                    'store_clerk_id' => $order['transfer_ckid'],
                    'transfer_ckid' => $transfer_ckid,
                    'transfer_spid' => $transfer_spid,
                    'transfer_ctime' => time(),
                    'is_clerk_shipping' => 1, //该字段做互转的中转字段
                    'is_clerk_claim' => 0, //该字段做互转的中转字段
                    'is_claim' => 1,
                    'is_shipping' => 0,
                    'is_first' => 1,
                    'shopper_id' => 0,
                    'is_store_clerk_id' => 1,
                    'is_transfer_ckid' => 1,
                    'is_single' => 0
                ]);

                $msg = '您有新的订单，请及时查收';
                $result_data = [];
                $result_data['msg'] = $msg;
                $result_data['type'] = 'success';
                $result_data_json = json_encode($result_data);
                //推送
                Shopper::messagePush($order['transfer_spid'],$result_data_json);//推送消息
                return $this->renderSuccess('操作成功');

            }elseif($stype==2){
                //转一秒到家

                $Shopper = (new Shopper()) -> where('id', $params['shopper_id'])->find();

                $data = [
                    'shop_supplier_id' => $order['shop_supplier_id'],
                    'store_id' => $order['store_id'],
                    'order_id' => $order['order_id'],
                    'image' => $params['image']??'',
                    'store_clerk_id' => $Shopper['id'],
                    'store_clerk_phone' => $Shopper['mobile'],
                    'ctype' => 1
                ];
                ProductClaim::createData($data);

                $is_first = $order['is_first'] == 1? 2:1;//是否第一次转一秒到家（1=否，2=是）



                $order->save([
                    'is_transfer' => 1,
                    'store_clerk_id' => $params['shopper_id'],//当前原配送员（特殊配送员）
                    'transfer_ckid' => $order['store_clerk_id'], //原配送员
                    'transfer_spid' => $order['store_id'],
                    'transfer_ctime' => time(),
                    'is_clerk_shipping' => 0, //该字段做互转的中转字段
                    'is_clerk_claim' => 0, //该字段做互转的中转字段
                    'is_first' => $is_first,
                    'shopper_id' => $params['shopper_id'],
                    'is_store_clerk_id' => 2,
                    'is_transfer_ckid' => $is_transfer_ckid
                ]);


                $is_store_clerk_id = 2;
                //取货后转单一定要拍照
                if($order['is_clerk_claim'] == 1){ //该字段做互转的中转字段用于判断是否取货
                    if(!isset($params['image'])||$params['image']==''){
                        return $this->renderError('请先拍照上传');
                    }
                }

                $msg = '您有新的订单，请及时查收';
                $result_data = [];
                $result_data['msg'] = $msg;
                $result_data['type'] = 'success';
                $result_data_json = json_encode($result_data);

                Shopper::messagePush($Shopper['id'],$result_data_json);//推送消息
                // Shopper::messagePush($params['shopper_id'],$result_data_json);//推送消息
            }elseif($stype==1){
                //跨店
                //查找店铺
                $clerk = Clerk::where(['clerk_id'=>$params['shopper_id']])->find();
                $store_id = $clerk['store_id'];
//                $order = $model->where(['order_id' => $params['order_id']])->find();

                //取货后转单一定要拍照
                if($order['is_claim'] == 1){
                    if(!isset($params['image'])||$params['image']==''){
                        return $this->renderError('请先拍照上传');
                    }
                }


                $data = [
                    'shop_supplier_id' => $order['shop_supplier_id'],
                    'store_id' => $store_id,
                    'order_id' => $order['order_id'],
                    'image' => $params['image'] ??'',
                    'store_clerk_id' => $clerk['clerk_id'],
                    'store_clerk_phone' => $clerk['mobile'],
                    'ctype' => 1
                ];
                ProductClaim::createData($data);
                //更新订单
                $order->save([
                    'is_transfer' => 1,
                    'store_clerk_id' => $params['shopper_id'],
                    'store_id' => $store_id,
                    'transfer_ckid' => $order['store_clerk_id'],
                    'transfer_spid' => $order['store_id'],
                    'transfer_ctime' => time(),
                    'is_clerk_shipping' => 0, //该字段做互转的中转字段
                    'is_clerk_claim' => 0, //该字段做互转的中转字段
                    'is_store_clerk_id' => 1,
                    'is_transfer_ckid' => $is_transfer_ckid


                ]);


                $msg = '您有新的订单，请及时查收';
                $result_data = [];
                $result_data['msg'] = $msg;
                $result_data['type'] = 'success';
                $result_data_json = json_encode($result_data);
                //推送
                Shopper::messagePush($order['store_id'],$result_data_json,1);//推送消息
            }else{
                //店内
//                $order = $model->where(['order_id' => $params['order_id']])->find();
                //取货后转单一定要拍照
                if($order['is_claim'] == 1){
                    if(!isset($params['image'])||$params['image']==''){
                        return $this->renderError('请先拍照上传');
                    }
                }

                //待接单的店员信息
                $clerk = (new Clerk()) -> where(['clerk_id'=>$params['shopper_id']])->find();
//                $clerk = (new Clerk()) -> where('clerk_id', $order['store_clerk_id'])->find();
                $data = [
                    'shop_supplier_id' => $order['shop_supplier_id'],
                    'store_id' => $order['store_id'],
                    'order_id' => $order['order_id'],
                    'image' => $params['image']??'',
                    'store_clerk_id' => $clerk['clerk_id'],
                    'store_clerk_phone' => $clerk['mobile'],
                    'ctype' => 1
                ];
                ProductClaim::createData($data);
                //更新订单
                $order->save([
                    'is_transfer' => 1,
                    'store_clerk_id' => $params['shopper_id'],
                    'transfer_ckid' => $order['store_clerk_id'],
                    'transfer_spid' => $order['store_id'],
                    'transfer_ctime' => time(),
                    'is_clerk_shipping' => 0, //该字段做互转的中转字段
                    'is_clerk_claim' => 0, //该字段做互转的中转字段
                    'is_store_clerk_id' => 1,
                    'is_transfer_ckid' => $is_transfer_ckid
                ]);

                $msg = '您有新的订单，请及时查收';
                $result_data = [];
                $result_data['msg'] = $msg;
                $result_data['type'] = 'success';
                $result_data_json = json_encode($result_data);
                //推送
                Shopper::messagePush($params['shopper_id'],$result_data_json);//推送消息
            }

            //将新订单写入redis
            (new OrderModel()) -> insertRedisOrder($params['order_id']);

            (new OrderModel()) ->addUserIdJson($params['shopper_id'],$params['order_id'],$order['user_id_json'],$is_store_clerk_id);

            return $this->renderSuccess('操作成功');
        }catch (\Exception $exception){
            return $this->renderError($exception->getMessage());
        }

    }

    /**
     * @Exp    取消转单
     * @Author Mr.Z
     * @Date   2024-03-06
     * @param  Request    $request [request.stype:类型：0内部，1一秒]
     * @return [type]              [description]
     */
    public function canceltransferOrder(Request $request)
    {
        try {
            $params = $request->param();
            $model = new OrderModel;
            $order = $model -> where('order_id',$params['order_id']) -> find();

            $user = $this->getUser();
            $clerk = Clerk::getByUser($user);
            if(!$clerk){
                $clerk = Shopper::shopperDetail($user['user_id']);
                $clerk_id = $clerk['id'];
            }else{
                $clerk_id = $clerk['clerk_id'];
            }
            if($order['store_clerk_id'] != $clerk_id && $order['transfer_ckid'] != $clerk_id){
                return $this->renderError('该订单不能取消');
            }

            $order_id_array[] = $params['order_id']; //模型的方法兼容批量取消订单
            $model -> canceltransferOrder($order_id_array,$user);
            return $this->renderSuccess('操作成功');
        }catch (\Exception $exception){
            return $this->renderError($exception->getMessage());
        }
    }

    /**
     * @Exp    确认转单
     * @Author Mr.Z
     * @Date   2024-03-06
     * @param  Request    $request [request.stype:类型：0内部，1一秒]
     * @return [type]              [description]
     */
    public function completeTransferOrder(Request $request)
    {
        try {
            $model = new OrderModel;
            $params = $request->param();
            $stype = $params['stype'];
            if($stype==1){
                //特殊配送
                $order = $model->where(['order_id' => $params['order_id']])->find();
                $order->save([
                    'transfer_oktime' => time()
                ]);
            }else{
                //内部
                $order = $model->where(['order_id' => $params['order_id']])->find();
                $order->save([
                    'transfer_oktime' => time()
                ]);
            }
            return $this->renderSuccess('操作成功');
        }catch (\Exception $exception){
            return $this->renderError($exception->getMessage());
        }
    }

    /**
     * 特殊配送员接单
     * @param Request $request
     * @return \think\response\Json
     */
    public function shopperReceiving(Request $request)
    {
        try {
            $params = $request->param();
            $model = new OrderModel;
            $user = $this->getUser();
            $model->shopperReceiving($params, $user);
            return $this->renderSuccess('操作成功');
        } catch (\Exception $exception) {
            return $this->renderError($exception->getMessage());
        }
    }



    public function deliveryCompleted(Request $request)
    {
        try {
            $params = $request->param();
            $user = $this->getUser();
//            $wxmodel = \app\supplier\model\order\Order::detail($params['order_id']);
            //测试和零元购不需要验证发货
//            if(!isset($params['gettest'])&&$wxmodel['pay_price']>0){
//                $wxmodel->wxDelivery();
//            }
            // 20240614 Mr.Z去掉测试模式
//            if($wxmodel['pay_price']>0){
//                $wxmodel->wxDelivery();
//            }
            $shopper = isset($params['shopper'])?true:false;
            OrderModel::deliveryCompleted($params, $user, $shopper);
            return $this->renderSuccess('操作成功');
        } catch (\Exception $exception) {
            return $this->renderError($exception->getMessage());
        }
    }

    public function asyncSaveCoord(Request $request)
    {
        try {
            $params = $request->param();
            OrderModel::asyncSaveCoord($params);
            return $this->renderSuccess('操作成功');
        } catch (\Exception $exception) {
            return $this->renderError($exception->getMessage());
        }
    }

    public function asyncGetCoord(Request $request)
    {
        $params = $request->param();
        $order = OrderModel::asyncGetCoord($params);
        return $this->renderSuccess('操作成功', $order);
    }

    public function detail($order_id, $pay_source = '')
    {
        // 订单详情
        $model = OrderModel::one(['order_id' => $order_id], ['product' => function ($query) {
            $query->with('image');
        }, 'user', 'address','productClaim','shopperUser','gift_product_order' =>['gift_product','file']]);

        $model['deliveryUser'] = OrderModel::getDeliveryUser($model['store_clerk_id'],$model['is_store_clerk_id']);
        $model['transferUser'] = OrderModel::getDeliveryUser($model['transfer_ckid'],$model['is_transfer_ckid']);
        $product_claim = [];
        if($model['productClaim']) {
            foreach ($model['productClaim'] as $key => $value) {
                $value['image_list'] = [];

                if ($value['image']) {
                    if(strstr($value['image'], ',')){
                        $value['image_list'] = explode(',',$value['image']);
                    }else{
                        $value['image_list'] = [$value['image']];
                    }
                    $product_claim[]= $value;
                }

            }

            $model['productClaim'] = $product_claim;
        }

        if($model['delivery_image']){
            if(strstr($model['delivery_image'], ',')){
                $model['delivery_image'] = explode(',',$model['delivery_image']);
            }else{
                $model['delivery_image'] = [$model['delivery_image']];
            }
        }



        // 剩余支付时间
        if ($model['pay_status']['value'] == 10 && $model['order_status']['value'] != 20 && $model['pay_end_time'] != 0) {
            $model['pay_end_time'] = $this->formatPayEndTime($model['pay_end_time'] - time());
        } else {
            $model['pay_end_time'] = '';
        }
        // 该订单是否允许申请售后
        $model['isAllowRefund'] = $model->isAllowRefund();
        $model['supplier']['supplier_user_id'] = (new SupplierUserModel())->where('shop_supplier_id', '=', $model['shop_supplier_id'])->value('supplier_user_id');
        $app = AppModel::detail();
        $mch_id = $app['mchid'];
        return $this->renderSuccess('', [
            'order' => $model,  // 订单详情
            'setting' => [
                // 积分名称
                'points_name' => SettingModel::getPointsName(),
                //是否开启客服
                'service_open' => SettingModel::getSysConfig()['service_open'],
                //店铺客服信息
                'mp_service' => ServiceModel::detail($model['shop_supplier_id']),
            ],
            'show_alipay' => PayService::isAlipayOpen($pay_source, $model['app_id']),
            'mch_id' => $mch_id
        ]);
    }

    public function claimProduct(Request $request)
    {
        $parmas = $request->param();
        $pc = ProductClaim::where('order_id', '=', $parmas['order_id'])->find();
//        if (!empty($pc)) return $this->renderError('请勿重复提交领取');
        $order = \app\api\model\order\Order::where('order_id', '=', $parmas['order_id'])->find();
        $clerk = Clerk::where('clerk_id', '=', $order['store_clerk_id'])->find();
        $data = [
            'shop_supplier_id' => $order['shop_supplier_id'],
            'store_id' => $order['store_id'],
            'order_id' => $order['order_id'],
            'image' => $parmas['image'],
            'store_clerk_id' => $order['store_clerk_id'],
            'store_clerk_phone' => $clerk['mobile'],
        ];
        ProductClaim::createData($data);
        $user = $this->getUser();
        $user_id = $user['user_id'];
        cache($user_id.'_'.$order['order_id'],1);
        $order-> where('order_id',$order['order_id']) -> update(['is_claim' => 1,'is_clerk_claim' => 1]);
        return $this->renderSuccess('操作成功');
    }

    /**
     * 添加备注
     * addRemarks
     * @param Request $request
     * \think\response\Json
     * @return \think\response\Json
     * @Author kevin
     * @date 2024/4/13 11:44
     */
    public function addRemarks(Request $request){
        $parmas = $request->param();
        $address_remarks = $parmas['address_remarks']??'';
        $store_remarks = $parmas['store_remarks']??'';
        $update_data = [];
        if($address_remarks){
            $update_data['address_remarks'] = $address_remarks;
        }
        if($store_remarks){
            $update_data['store_remarks'] = $store_remarks;
        }
        (new OrderModel()) -> where('order_id', $parmas['order_id'])->update($update_data);
        return $this->renderSuccess('操作成功');
    }

    /**
     *配送端新增备注列表
     * getRemarksList
     * \think\response\Json
     * @return \think\response\Json
     * @Author kevin
     * @date 2024/6/15 10:27
     */
    public function getRemarksList()
    {
        $list = Remarks::where('is_delete',0) -> column('title');
        return $this->renderSuccess('', compact('list'));
    }

    /**
     * 用户自提
     * userPickup
     * @param Request $request
     * \think\response\Json
     * @return \think\response\Json
     * @Author kevin
     * @date 2024/4/16 15:53
     */
    public function userPickup(Request $request)
    {

        $params = $request->param();
        $order = (new OrderModel()) -> where(['order_id' => $params['order_id']])->find();

        $user = $this->getUser();
        $clerk = Clerk::getByUser($user);
        $order_id = $params['order_id'];
        $delivery_image = $params['delivery_image'];
        $update_data['delivery_type'] = 20;
        $update_data['delivery_image'] = $delivery_image;
        $update_data['extract_store_id'] = $clerk['store_id'];
        $update_data['extract_clerk_id'] = $clerk['clerk_id'];
        $update_data['delivery_status'] = 20;
        $update_data['receipt_status'] = 20;
        $update_data['order_status'] = 30;
        $update_data['receipt_time'] = time();

        //推荐订单
        try {
            $tresponse = OrderRefereeModel::RefereeOrderCompleted($order);
            //20240314 joey 推广奖励优惠券
            (new OrderCompleteService())->onOrderNumCoupon([$order]);
            //20240409 joey 购买商品赠送优惠券
            self::giveCoupon($order);
        } catch (\Exception $e) {
            log_write('写入错误：' . $e->getMessage());
        }
        if ($tresponse) {
            $UserModel = new UserModel();
            $refrs     = $UserModel->where('user_id', '=', $order['user_id'])->find();
            if ($refrs) $UserModel->sumInviteMoney($refrs['referee_id'], $order['pay_price']);
        }


        //触发微信小程序发货
        $wxmodel = \app\supplier\model\order\Order::detail($params['order_id']);
        $wxmodel->wxDelivery();

        (new OrderModel()) -> where('order_id', $order_id)->update($update_data);
        return $this->renderSuccess('操作成功');
    }


    /**
     * 转单万服平台
     * @param Request $request
     * @return \think\response\Json
     * @throws \GuzzleHttp\Exception\GuzzleException
     * @Author joey
     * @date 2024/6/5 16:58
     */
    public function transferOrderWf(Request $request)
    {
        try {
            $params = $request->param();
            $model  = new OrderModel;
            $order  = $model->with(['product.image', 'address', 'deliveryUser'])->where('order_id', $params['order_id'])->find();

            $user = $this->getUser();
            $clerk = Clerk::getByUser($user);

            if (!$clerk) {
                $clerk       = Shopper::shopperDetail($user['user_id']);
                $jmd_deliver = [
                    'uid'      => $clerk['uid'],
                    'username' => $clerk['username'],
                    'mobile'   => $clerk['mobile'],
                    'avatar'   => $clerk['avatar'],
                ];
            } else {
                $jmd_deliver = [
                    'uid'      => $clerk['user_id'],
                    'username' => $clerk['real_name'],
                    'mobile'   => $clerk['mobile'],
                ];
            }

            $address = OrderAddress::find($order['address']['order_address_id']);
            $store   = Store::find($order['store_id']);

            $goods_info = [];

            $item = [];

            foreach ($order['product'] as $product) {
                $goods_info[] = [
                    'product_name'   => $product['product_name'],
                    'product_attr'   => $product['product_attr'],
                    'image'          => base_url().$product['image']['file_name'],
                    'product_price'  => $product['product_price'],
                    'total_num'      => $product['total_num'],
                    'product_weight' => $product['product_weight'],
                ];
                $item[] = [
                    'weight' => $product['product_weight'],
                    'num'    => $product['total_num'],
                ];
            }

            $data = [
                'type'            => 7,
                'pickup_name'     => $store['store_name'] ?? '',
                'pickup_address'  => $store->getFullAddress() ?? '',
                'pickup_phone'    => $store['phone'] ?? '',
                'deliver_name'    => $order['address']['name'] ?? '',
                'deliver_address' => $address->getFullAddress() ?? '',
                'deliver_phone'   => $order['address']['phone'] ?? '',
                'remark'          => $order['address_remarks'],
                'item'            => $item,
                'user_mobile'     => $jmd_deliver['mobile'],
                'user_name'       => $jmd_deliver['username'],
                'goods_info'      => json_encode($goods_info, JSON_UNESCAPED_UNICODE),
                'jmd_deliver'     => json_encode($jmd_deliver, JSON_UNESCAPED_UNICODE),
                'amount'          => 0,//暂时未定
                'deliveryman_id'  => $params['shopper_id'],
                'transfer_image'  => $params['transfer_image'] ?? '',
            ];

            $client = new Client();

            $response = $client->post('https://wf.jiumaioda.com/api/index/transferOrder?app_id=10001',[
                'json'    => $data,
                //'headers' => []
            ]);

            if ($response->getStatusCode() == 200) {
                $results = json_decode($response->getBody(), true);
                if (isset($results) && $results['code'] == 1) {
                    return $this->renderSuccess('操作成功');
                } else {
                    return $this->renderError($results['msg']);
                }
            } else {
                return $this->renderSuccess('请求失败');
            }
        }catch (\Exception $exception){
            log_write('酒秒达转单万服操作失败：' . $exception->getMessage());
            return $this->renderError($exception->getMessage());
        }
    }
}
